<!DOCTYPE html>
<html lang="zh">
<head>
    <th:block th:include="include :: header('文件上传')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<style type="text/css">
    table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m" id="upload">
                    <ul>
                        <li>
                            <label class="control-label is-required">文件标题：</label>
                            <input type="text" name="documenttitle" required/>
                            <span style="color: darkgrey">标题名称在1~50位字符,且不为空</span>
                        </li>
                    </ul>
                    <div class="form-group">
                        <div class="fileinput fileinput-new input-group" data-provides="fileinput">
                            <div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div>
                            <span class="input-group-addon btn btn-white btn-file"><span class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input type="file"></span>
                            <a href="#" class="input-group-addon btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        </div>
                    </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: jasny-bootstrap-js" />
<script type="text/javascript">

    var prefix = ctx + 'product/document';

    function submitHandler() {
        if ($.validate.form("upload")){
            var files = $("input[type=file]")[0].files;
            if (files.length <= 0){
                alert("请选择文件再上传");
                return;
            }
            var formdata = new FormData();
            formdata.enctype = "multipart/form-data";
            formdata.append('file',files[0]);
            var a = $('input[name=documenttitle]').val()
            formdata.append('documenttitle',$('input[name=documenttitle]').val());
            var businesskey = '[[${businesskey}]]';
            formdata.append('businesskey',businesskey);
            $.ajax({
                type: 'post',
                url: prefix + '/upload',
                dataType: 'json',
                contentType: false,
                data: formdata,
                processData: false,
                cache: false,
                success: function(result) {
                    $.operate.successCallback(result);
                }
            })
        }
    }
</script>
</body>
</html>
